<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>YUI Lang Tests</title>
</head>

<body class="yui-skin-sam">

<iframe name="xframe" id="xframe" src="assets/xframe.html"></iframe>

<h1>Lang Tests</h1>
<p><input type="button" value="Run Tests" id="btnRun" disabled="true" /></p>

<script type="text/javascript" src="../../../build/yui/yui.js"></script>
<script type="text/javascript">

(function() {
    YUI({
        base: "../../../build/",
        filter: "debug",
        useConsole: true,
        logExclude: {Dom: true, Selector: true, Node: true, attribute: true, base: true, event: true, widget: true}
    }).use("dump", "test", "console", "event-custom", function(Y) {

        Y.log(typeof NaN);

        var button = Y.get('#btnRun'),
            Assert = Y.Assert;

        // Set up the page
        button.set("disabled", false);
        Y.on("click", function() {
            Y.Test.Runner.run();
        }, button);

        var myConsole = new Y.Console().render();

        var testObject = new Y.Test.Case({
            name: "Lang tests",

        test_is_array: function() {
            Assert.isTrue(Y.Lang.isArray([1, 2]), "Array literals are arrays");
            Assert.isFalse(Y.Lang.isArray({"one": "two"}), "Object literals are not arrays");

            var a = new Array();
            a["one"] = "two";
            Assert.isTrue(Y.Lang.isArray(a), "Associative array are arrays");

            Assert.isFalse(Y.Lang.isArray(document.getElementsByTagName("body")),
                    "Element collections are array-like, but not arrays");

            Assert.isFalse(Y.Lang.isArray(null), "null is not an array");
            Assert.isFalse(Y.Lang.isArray(''), "'' is not an array");
            Assert.isFalse(Y.Lang.isArray(undefined), "undefined is not an array");

            Assert.isTrue(Y.Lang.isArray(xframe.arr), "Cross frame array failure");
            Assert.isFalse(Y.Lang.isArray(xframe.far), "Cross frame fake array failure");
            Assert.isFalse(Y.Lang.isArray(xframe.obj), "Cross frame object failure");
            Assert.isFalse(Y.Lang.isArray(xframe.fun), "Cross frame function failure");
            Assert.isFalse(Y.Lang.isArray(xframe.boo), "Cross frame boolean failure");
            Assert.isFalse(Y.Lang.isArray(xframe.str), "Cross frame string failure");
            Assert.isFalse(Y.Lang.isArray(xframe.nul), "Cross frame null failure");
            Assert.isFalse(Y.Lang.isArray(xframe.und), "Cross frame undefined failure");
        
            // alert(xframe.arr.constructor.prototype == Array.prototype);
            // alert(xframe.arr.constructor.prototype == xframe.Array.prototype);
        },

        test_is_boolean: function() {
            Assert.isTrue(Y.Lang.isBoolean(false), "false failed boolean check");
            Assert.isFalse(Y.Lang.isBoolean(1), "the number 1 is not a boolean");
            Assert.isFalse(Y.Lang.isBoolean("true"), "the string 'true' is not a boolean");
        },

        test_is_function: function() {
            Assert.isTrue(Y.Lang.isFunction(function(){}), "a function is a function");
            Assert.isFalse(Y.Lang.isFunction({foo: "bar"}), "an object is not a function");

            Assert.isTrue(Y.Lang.isFunction(xframe.fun), "Cross frame function failure");
            Assert.isFalse(Y.Lang.isFunction(xframe.arr), "Cross frame array failure");
            Assert.isFalse(Y.Lang.isFunction(xframe.obj), "Cross frame object failure");
            Assert.isFalse(Y.Lang.isFunction(xframe.boo), "Cross frame boolean failure");
            Assert.isFalse(Y.Lang.isFunction(xframe.str), "Cross frame string failure");
            Assert.isFalse(Y.Lang.isFunction(xframe.nul), "Cross frame null failure");
            Assert.isFalse(Y.Lang.isFunction(xframe.und), "Cross frame undefined failure");

        },
    
        test_is_null: function() {
            Assert.isTrue(Y.Lang.isNull(null), "null is null");
            Assert.isFalse(Y.Lang.isNull(undefined), "undefined is not null");
            Assert.isFalse(Y.Lang.isNull(""), "empty string is not null");
        },
    
        test_is_number: function() {
            Assert.isTrue(Y.Lang.isNumber(0), "0 is a number");
            Assert.isTrue(Y.Lang.isNumber(123.123), "123.123 is a number");
            Assert.isFalse(Y.Lang.isNumber('123.123'), "the string '123.123' is not a number, even though it can be cast into one");
            Assert.isFalse(Y.Lang.isNumber(1/0), "undefined numbers and infinity are not numbers we want to use");
        },
    
        test_is_object: function() {
            Assert.isTrue(Y.Lang.isObject({}), "an object is an object");
            Assert.isTrue(Y.Lang.isObject(function(){}), "a function is an object");
            Assert.isTrue(Y.Lang.isObject([]), "an array is an object");
            Assert.isFalse(Y.Lang.isObject(1), "numbers are not objects");
            Assert.isFalse(Y.Lang.isObject(true), "boolean values are not objects");
            Assert.isFalse(Y.Lang.isObject("{}"), "strings are not objects");
            Assert.isFalse(Y.Lang.isObject(null), "null should return false even though it technically is an object");

            Assert.isTrue(Y.Lang.isObject(xframe.obj), "Cross frame object failure");
            Assert.isTrue(Y.Lang.isObject(xframe.fun), "Cross frame function failure");
            Assert.isTrue(Y.Lang.isObject(xframe.arr), "Cross frame array failure");
            Assert.isFalse(Y.Lang.isObject(xframe.boo), "Cross frame boolean failure");
            Assert.isFalse(Y.Lang.isObject(xframe.str), "Cross frame string failure");
            Assert.isFalse(Y.Lang.isObject(xframe.nul), "Cross frame null failure");
            Assert.isFalse(Y.Lang.isObject(xframe.und), "Cross frame undefined failure");

        },
    
        test_is_string: function() {
            Assert.isTrue(Y.Lang.isString("{}"), "a string is a string");
            Assert.isFalse(Y.Lang.isString({foo: "bar"}), "an object is not a string");
            Assert.isFalse(Y.Lang.isString(123), "a number is not a string");
            Assert.isFalse(Y.Lang.isString(true), "boolean values are not strings");
        },

        test_is_undefined: function() {
            Assert.isTrue(Y.Lang.isUndefined(undefined), "undefined is undefined");
            Assert.isFalse(Y.Lang.isUndefined(false), "boolean false is not undefined");
            Assert.isFalse(Y.Lang.isUndefined(null), "null is not undefined");
        },

        test_trim: function() {
            Assert.areEqual(Y.Lang.trim("  My String"), "My String");
            Assert.areEqual(Y.Lang.trim("My String  "), "My String");
            Assert.areEqual(Y.Lang.trim("  My String  "), "My String");
            Assert.areEqual(Y.Lang.trim(null), null);
            Assert.areEqual(Y.Lang.trim(undefined), undefined);
            Assert.areEqual(Y.Lang.trim({}), "[object Object]");
        },

        test_isValue: function() {
            Assert.isFalse(Y.Lang.isValue(null), "null should be false");
            Assert.isFalse(Y.Lang.isValue(undefined), "undefined should be false");
            Assert.isFalse(Y.Lang.isValue(parseInt("adsf", 10)), "NaN should be false");
            Assert.isFalse(Y.Lang.isValue(1/0), "undefined numbers and infinity should be false");
            Assert.isTrue(Y.Lang.isValue(new Date()), "date should be true");
            Assert.isTrue(Y.Lang.isValue(""), "Empty string should be true");
            Assert.isTrue(Y.Lang.isValue(false), "false should be true");
        },

        test_isDate: function() {
            Assert.isFalse(Y.Lang.isDate(null), "null should be false");
            Assert.isFalse(Y.Lang.isDate(undefined), "undefined should be false");
            Assert.isFalse(Y.Lang.isDate(parseInt("adsf", 10)), "NaN should be false");
            Assert.isFalse(Y.Lang.isDate(1/0), "undefined numbers and infinity should be false");
            Assert.isFalse(Y.Lang.isDate(NaN), "NaN should be false");
            Assert.isTrue(Y.Lang.isDate(new Date()), "date should be true");
            Assert.isFalse(Y.Lang.isDate(""), "Empty string should be false");
            Assert.isFalse(Y.Lang.isDate(false), "false should be false");
            Assert.isFalse(Y.Lang.isDate(xframe.fun), "Cross frame function should be false");
            Assert.isTrue(Y.Lang.isDate(xframe.dat), "Cross frame date should be true");
        }
            
        });
        

        Y.Test.Runner.add(testObject);
        Y.Test.Runner.run();
    });
})();
</script>
</body>
</html>
